using System;
using ShouldIt.Core;

namespace ShouldIt.Clr.Fluent
{
    public class ShouldBase<T, TTarget, TBe> where T : ShouldBase<T, TTarget, TBe>
    {
        protected readonly IAssertProvider assertProvider;
        internal TTarget Target { get; private set; }
        internal bool Negate { get; private set; }

        public ShouldBase(TTarget target, IAssertProvider assertProvider)
        {
            this.assertProvider = assertProvider;
            Target = target;
        }

        public T Not
        {
            get
            {
                Negate = !Negate;
                return (T)this;
            }
        }

        public TBe Be
        {
            get { return (TBe)Activator.CreateInstance(typeof(TBe), this, assertProvider); }
        }

        public TTarget Equal(TTarget expected)
        {
            if (Negate)
            {
                assertProvider.AreNotEqual(expected, Target);
            }
            else
            {
                assertProvider.AreEqual(expected, Target);
            }
            return Target;
        }
    }
}